/**
 * @file   1122.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sat May 29 03:51:28 2021
 * 
 * @brief  PAT 1122:Judge a solution is a Hamilton cycle or not
 * 
 * 
 */
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
class Graph{
private:
    int AdjMat[205][205];
    int Nv;
    int Ne;
    int checknum;
public:
    Graph();
    void check();
    void checkone();
};
Graph::Graph(){
    cin>>Nv>>Ne;
    for(int i=1;i<=Nv;i++){
	for(int j=1;j<=Nv;j++){
	    AdjMat[i][j]=0;
	}
    }
    for(int i=0;i<Ne;i++){
	int a,b;
	cin>>a>>b;
	AdjMat[a][b]=1;
	AdjMat[b][a]=1;
    }
    cin>>checknum;
}
void Graph::check(){
    for(int i=0;i<checknum;i++){
	checkone();
    }
}
void Graph::checkone(){
    int nl;
    cin>>nl;
    vector<int> path;
    vector<bool> passed;
    passed.resize(Nv+1);
    for(int i=0;i<nl;i++){
	int d;
	cin>>d;
	path.push_back(d);
    }
    if(nl!=(Nv+1)){
	cout<<"NO"<<endl;
	return;
    }
    else{
	if(path[0]!=path[nl-1]){
	    cout<<"NO"<<endl;
	    return;
	}else{
	    for(int i=0;i<nl-1;i++){
		passed[path[i]]=true;
		if(AdjMat[path[i]][path[i+1]]==0){
		    cout<<"NO"<<endl;
		    return;
		}
	    }
	    for(int i=1;i<=Nv;i++){
		if(passed[i]==false){
		    cout<<"NO"<<endl;
		    return;
		}
	    }
	}
    }
    cout<<"YES"<<endl;
    return;
}
int main(){
    Graph G;
    G.check();
}
